home *** CD-ROM | disk | FTP | other *** search
/ Totally AMOS / Totally AMOS - Issue 1 (1991-11)(Tucker, Len - Tucker, Anne).adf / source_progs / 3d_rotating_shapes.AMOS / 3d_rotating_shapes.amosSourceCode
AMOS Source Code  |  1991-09-17  |  8KB  |  233 lines

  1. '3D Prospective demo   
  2. 'Written by Paul Townsend of Technical Fred Software   
  3. 'for Totally Amos  
  4. 'Suggestion : Run this program through your complier 
  5. 'It makes a lot more responsive  
  6. 'If you pinch any ideas from this code then please give me and Totally Amos  
  7. 'a mention in your credits 
  8. Break Off : Rem Do not remove this line, you can quit by pressing return   
  9. 'at the how many sides prompt, if you were able to break in to the         
  10. 'program then you may find that you could not control the editor     
  11. 'as the keyboard response time is speeded up in the program      
  12. 'but is reset to something usable when input or quit is used     
  13. Curs Off 
  14. Fade 5 : Wait 5*15
  15. Global SCR,SIZE
  16. Key Speed 1,1
  17. Screen Open 0,320,256,2,Lowres
  18. Flash Off 
  19. Curs Off 
  20. Cls 0
  21. Hide On 
  22. Palette 0,0
  23. Screen Open 1,320,256,2,Lowres
  24. Flash Off 
  25. Curs Off 
  26. Cls 0
  27. Hide On 
  28. Palette 0,0
  29. Rem                           ************************************************   
  30. Degree : Rem                  * All the trig is worked out before hand       *  
  31. Dim X#(720),Y#(720) : Rem     * This speeds up drawing in the main draw loop *   
  32. For F=0 To 720 : Rem          *                                              *  
  33.    X#(F)=160+100*Sin(F) : Rem *                                              * 
  34.    Y#(F)=128+100*Cos(F) : Rem *                                              * 
  35. Next F : Rem                  ************************************************
  36. 10
  37. Screen 1
  38. Screen To Front 1
  39. Cls 
  40. Key Speed 30,5
  41. Fade 5,0,$F0
  42. Clear Key 
  43. Input "How many sides (1-360) ";SIDES
  44. If SIDES<0 or SIDES>360 Then Goto 10
  45. If SIDES=0 Then QUIT : Goto 10
  46. Curs Off 
  47. Key Speed 1,1
  48. SIZE=50
  49. TX=160 : TY=128
  50. Print "Press Help during rotation for more info"
  51. 20
  52. For F=0 To 720
  53.    X#(F)=160+SIZE*Sin(F)
  54.    Y#(F)=128+SIZE*Cos(F)
  55. Next F
  56. Fade 5 : Wait 5*15
  57. Cls 0
  58. Screen 0 : Cls 0 : Wait Vbl 
  59. Screen 1 : Cls 0 : Wait Vbl 
  60. Screen Abs(SCR-1)
  61. Fade 5,0,$F0 : Wait 5*15
  62. Screen To Front SCR
  63. Screen SCR
  64. Fade 5,0,$F0 : Wait 5*15
  65. 'This is the main drawing loop   
  66. 'insted of explaining it all line by line, I will explain the theory       
  67. 'Imagine a circle placed in the centre of the screen     
  68. 'now draw from a fixed point on the screen to several points on      
  69. 'the circumference.        
  70. 'Now draw lines from all of these points on the circumference      
  71. 'to the point on the circumference with is next to it.     
  72. 'If you then clear the screen and redraw with all the points moved     
  73. 'slightly round the circumference then you get the effect of rotation    
  74. Do 
  75.    For F=0 To 360
  76.       Add SCR,1,0 To 1
  77.       Screen To Front SCR
  78.       Wait Vbl 
  79.       Screen Abs(SCR-1)
  80.       Wait Vbl 
  81.       Cls 0
  82.       For L=0 To 360-(360/SIDES) Step 360/SIDES
  83.          Draw MEMX,MEMY To X#(F+L),Y#(F+L)
  84.          MEMX=X#(F+L)
  85.          MEMY=Y#(F+L)
  86.          Draw To TX,TY
  87.       Next L
  88.       K$=Inkey$
  89.       REDO:
  90.       If K$="8" Then Dec TY
  91.       If K$="2" Then Inc TY
  92.       If K$="4" Then Dec TX
  93.       If K$="6" Then Inc TX
  94.       If K$="7" Then Dec TX : Dec TY
  95.       If K$="1" Then Dec TX : Inc TY
  96.       If K$="3" Then Inc TX : Inc TY
  97.       If K$="9" Then Inc TX : Dec TY
  98.       If K$="5" Then TX=160 : TY=128
  99.       If Key State(95) Then INFO
  100.       If Key State(76) Then Add SIZE,10,10 To 100 : Repeat : Until Not Key State(76) : MESSAGE["Increasing Size"] : Goto 20
  101.       If Key State(77) Then Add SIZE,-10,10 To 100 : Repeat : Until Not Key State(77) : MESSAGE["Decreasing Size"] : Goto 20
  102.       If Key State(79) Then Add SIDES,-1,1 To 30 : Repeat : Until Not Key State(79)
  103.       If Key State(78) Then Add SIDES,1,1 To 30 : Repeat : Until Not Key State(78)
  104.       Exit If K$=" "
  105.       Clear Key 
  106.    Next F
  107.    Exit If K$=" "
  108. Loop 
  109. Screen 0 : Fade 5 : Wait 5*15
  110. Screen 1 : Fade 5 : Wait 5*15
  111. Goto 10
  112. Procedure INFO
  113.    Screen 0
  114.    Fade 5
  115.    Wait 5*15
  116.    Screen 1
  117.    Fade 5
  118.    Wait 5*15
  119.    Screen Open 2,640,256,2,Hires
  120.    Flash Off 
  121.    Curs Off 
  122.    Palette 0,0
  123.    Hide On 
  124.    Cls 0
  125.    Centre("3D Prospective Demo")
  126.    Print 
  127.    Print "Welcome to the 3D Prospective demo"
  128.    Print "Coded By Paul Townsend of Technical Fred Software"
  129.    Print "Written for TOTALLY AMOS on 31 August 1991"
  130.    Print ""
  131.    Print "Instructions for use"
  132.    Print ""
  133.    Print "At the start of the demo  you  will  be asked for the number of"
  134.    Print "sides that you want the shape  to  have,  just type in a number"
  135.    Print "between 1 and  360  and  press  RETURN,  the  program will then"
  136.    Print "continue, I find that low numbers of sides work best, ie below"
  137.    Print "10."
  138.    Print ""
  139.    Print "When the shape is rotating you have the following options:"
  140.    Print ""
  141.    Print "SPACE: Stop rotating and ask you how many sides you require for"
  142.    Print "the next shape. If you don't  type  in  a number and just press"
  143.    Print "return then the program will quit."
  144.    Print ""
  145.    Print "Keys on the number pad move the centre about which the shape is"
  146.    Print "rotated. Try them, you will get the idea"
  147.    Print ""
  148.    Print "The keys move the centre in the direction that they point i.e.:"
  149.    Print ""
  150.    Print " The cursor keys change      7      9"
  151.    Print " the size of the  shape       \  8 /"
  152.    Print " without  changing  the        \ ^/"
  153.    Print " shapes  position  i.e.    4<----5---->4"
  154.    Print "                               / V\"
  155.    Print "  ^ Add 10 to radius          /    \"
  156.    Print "  V Take 10 from radius      1      3"
  157.    REFRESH
  158.    Print "The 5 key in the middle will return the rotation centre back to"
  159.    Print "the centre of the screen."
  160.    Print ""
  161.    Print "How it all works"
  162.    Print "================"
  163.    Print ""
  164.    Print "What are you asking me for ? I only wrote the program !"
  165.    Print ""
  166.    Print "Seriously though, the 3D image is of course a bit of a con job,"
  167.    Print "it's all done using a circle as  a  point to draw the lines to,"
  168.    Print "the more places on the circle  you  use at once, the more sides"
  169.    Print "the shape has.You then define a  fixed point, and draw from the"
  170.    Print "points on the circumference of the  circle to it (This point is"
  171.    Print "the one you move with the key pad.)"
  172.    Print ""
  173.    Print "Believe it or not, that's just about all there is to it."
  174.    Print ""
  175.    Print "If you wish to use parts of  this program for your own demos or"
  176.    Print "games etc. then all I ask is  that I get a mention somewhere in"
  177.    Print "your program i.e credits screen or Rem statement etc."
  178.    Print ""
  179.    Print "Also if you would like any  audio  or video digitising done for"
  180.    Print "your   demo   or    game    then    please    contact   me   at"
  181.    Print "Technical Fred Software"
  182.    Print "Tel. (061) 703 7842"
  183.    Print ""
  184.    Print "I would also welcome any comments about this, or any other bits"
  185.    Print "of code that I have written."
  186.    Print 
  187.    Print "Paul Townsend 11:25pm 31 August 1991"
  188.    REFRESH
  189.    Screen Abs(SCR-1)
  190.    Fade 5,0,$F0 : Wait 5*15
  191.    Screen To Front SCR
  192.    Screen SCR
  193.    Fade 5,0,$F0 : Wait 5*15
  194.    Clear Key 
  195. End Proc
  196. Procedure REFRESH
  197.    Print 
  198.    Centre("Press RETURN to continue")
  199.    Fade 5,0,$FFF
  200.    Wait 5*15
  201.    Clear Key 
  202.    Repeat 
  203.    Until Inkey$=Chr$(13)
  204.    Wait Key 
  205.    Fade 5
  206.    Wait 5*15
  207.    Cls 
  208.    Cls 0
  209. End Proc
  210. Procedure QUIT
  211.    Cls 
  212.    Cls 0
  213.    Print "Really Quit ? (Y/N)"
  214.    FLAG=-1
  215.    Do 
  216.       A$=Inkey$
  217.       If Upper$(A$)="Y" Then FLAG=1
  218.       If Upper$(A$)="N" Then FLAG=0
  219.       Exit If FLAG<>-1
  220.    Loop 
  221.    If FLAG=1 Then Key Speed 30,5 : Fade 5 : Wait 5*15 : Edit 
  222. End Proc
  223. Procedure MESSAGE[MESS$]
  224.    Screen SCR
  225.    Locate 0,0
  226.    Centre("Please Wait")
  227.    Print 
  228.    Centre(MESS$)
  229.    Print 
  230.    MESS$=Str$(SIZE)
  231.    MESS$=MESS$-" "
  232.    Centre("to "+MESS$)
  233. End Proc